home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 June / CHIP Haziran 2001.iso / prog / haziran / 19 / setup.exe / data.z / speaker_gui.c < prev    next >
C/C++ Source or Header  |  2001-04-11  |  3KB  |  110 lines

  1. ////////////////////////////////////////////////////////////////
  2. // File - speaker_gui.c
  3. //
  4. // This application plays a tone to the speaker, and is
  5. // controlled via a graphical user interface.
  6. // The speaker is accessed directly on the motherboard, using
  7. // WinDriver functions.
  8. // 
  9. ////////////////////////////////////////////////////////////////
  10.  
  11. #include <windows.h>
  12. #include "resource.h"
  13. #include "../speaker/speaker_lib.h"
  14. #include <stdio.h>
  15.  
  16. BOOL PASCAL MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  17. BOOL PASCAL AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  18.  
  19. SPEAKER_HANDLE hSpeaker = NULL;
  20. HINSTANCE ghInstance;
  21.  
  22. // The main window.
  23. // WinMain() opens a handle for speaker, and then creates the main window.
  24. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  25. {
  26.     ghInstance = hInstance;
  27.  
  28.     if (!SPEAKER_Open(&hSpeaker))
  29.     {
  30.         char msg[256];
  31.         sprintf (msg, "Error while opening speaker hardware:\n%s", SPEAKER_ErrorString);
  32.         MessageBox(NULL, msg, "Speaker Sample", MB_OK | MB_ICONERROR);
  33.         return FALSE;
  34.     }
  35.  
  36.     // create the Speaker window
  37.     DialogBoxParam(hInstance, MAKEINTRESOURCE(PLAYTONEDLGBOX), NULL, MainDlgProc, 0);
  38.  
  39.     SPEAKER_Close(hSpeaker);
  40.  
  41.     return 0;
  42.  
  43. // This is the About dialog Window Proc.
  44. BOOL PASCAL AboutDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  45. {
  46.     switch (uMsg)
  47.     {
  48.     case WM_INITDIALOG:
  49.         return TRUE;
  50.  
  51.     case WM_COMMAND:
  52.         if (LOWORD(wParam) == IDD_OK)
  53.         {
  54.             EndDialog(hDlg, TRUE);
  55.             return TRUE;
  56.         }
  57.         break;
  58.     }
  59.     return FALSE;
  60. }
  61.  
  62. // This is the Speaker Main dialog Window Proc.
  63. BOOL PASCAL MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  64. {
  65.     switch (uMsg)
  66.     {
  67.     case WM_INITDIALOG:
  68.         SetDlgItemText(hDlg, IDC_FREQ, "440");
  69.         SetDlgItemText(hDlg, IDC_DURATION, "1000");
  70.         return TRUE;
  71.  
  72.     case WM_COMMAND:
  73.         switch (LOWORD(wParam))
  74.         {
  75.         case IDD_PLAY_TONE:
  76.             {
  77.                 DWORD dwHertz = GetDlgItemInt(hDlg, IDC_FREQ, NULL, FALSE);
  78.                 DWORD dwMilli = GetDlgItemInt(hDlg, IDC_DURATION, NULL, FALSE);
  79.                 if (dwHertz && dwMilli) 
  80.                     SPEAKER_Tone(hSpeaker, dwHertz, dwMilli);
  81.                 break;
  82.             } 
  83.  
  84.         case IDD_CLOSE:
  85.             EndDialog(hDlg, TRUE);
  86.             return TRUE;
  87.         
  88.         case  IDC_PLAY_CHIME:
  89.             SPEAKER_Tone(hSpeaker, 440, 400);
  90.             SPEAKER_Tone(hSpeaker, 329, 200);
  91.             SPEAKER_Tone(hSpeaker, 1, 10);
  92.             SPEAKER_Tone(hSpeaker, 329, 200);
  93.             SPEAKER_Tone(hSpeaker, 369, 400);
  94.             SPEAKER_Tone(hSpeaker, 329, 800);
  95.             SPEAKER_Tone(hSpeaker, 415, 400);
  96.             SPEAKER_Tone(hSpeaker, 440, 600);
  97.             break;
  98.  
  99.         case IDC_ABOUT:
  100.             DialogBoxParam(ghInstance, MAKEINTRESOURCE(ABOUTDLGBOX), NULL, AboutDlgProc, 0);
  101.             break;
  102.  
  103.         }
  104.         break;
  105.     }
  106.  
  107.     return FALSE;
  108. }
  109.